package com.buer.storage.controller;

import com.buer.storage.commom.JsonResult;
import com.buer.storage.dto.*;
import com.buer.storage.entity.*;
import com.buer.storage.service.CorderService;
import com.buer.storage.vo.R;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/corder")
public class CorderController {
    @Resource
    private CorderService corderService;

    //增加盘点单所有信息
    @PostMapping("/insertCorder.do")
    public R insert(@RequestBody CorderStorageDto corderStorageDto){
        if (corderService.insertCorder(corderStorageDto) > 0) {

            return R.setR(1, "盘点单保存成功", null);
        }

        return R.setR(0,"盘点单保存失败",null);
    }
    @PostMapping("/selectByAll.do")
    public JsonResult selectByAll(@RequestBody Map<String,Object> params){
        PageInfo<Corder> entityList = corderService.selectByAll(params);
        Map result=new HashMap<>();
        result.put("total",entityList.getTotal());
        result.put("list",entityList.getList());
        return new JsonResult(1,result);
    }

    //根据盘点单ID查询盘点单信息
    @GetMapping("/findCorderAllById.do")
    public List<CorderStorageDto> findCorderAllById(Integer checkId){
        List<CorderStorageDto> corderAllById = corderService.findCorderAllById(checkId);
        return corderAllById;
    }

    //查询所有盘点单信息
    @GetMapping("/findCorderAll")
    public List<CorderDto> findCorderAll(){
        List<CorderDto> corderAll = corderService.findCorderAll();
        return corderAll;
    }

    //根据盘点单ID删除盘点单信息
    @GetMapping("/deleteCorderAllById")
    public R deleteCorderAllById(Integer checkId){
        if(corderService.deleteCorderAllById(checkId)>0){
            return R.setR(1,"删除盘点单成功",null);
        }
        return R.setR(0,"删除盘点单失败",null);
    }

    //更新盘点单信息
    @PostMapping("/updateCorderdetails.do")
    public R updateCorderdetails(@RequestBody CorderStorageDto corderStorageDto) {
        if (corderService.updateCorderdetails(corderStorageDto) > 0) {
            return R.setR(1, "更新盘点单成功", null);
        }
        return R.setR(0, "更新盘点单失败", null);
    }

    @GetMapping("/findStockByWarehouseId")
    public List<StockDto> findStockByWarehouseId(Integer warehouoseId){
        List<StockDto> stockByWarehouseId = corderService.findStockByWarehouseId(warehouoseId);
        return stockByWarehouseId;
    }

    @GetMapping("/findStockByProdArea")
    public List<StockDto> findStockByProdArea(Integer prodArea,Integer warehouseId){
        List<StockDto> stockByprodArea = corderService.findStockByProdArea(prodArea,warehouseId);
        return stockByprodArea;
    }

    @GetMapping("/findStockByProdDepart")
    public List<StockDto> findStockByProdDepart(Integer prodDepart,Integer prodArea,Integer warehouseId){
        List<StockDto> stockByprodDepart = corderService.findStockByProdDepart(prodDepart,prodArea,warehouseId);
        return stockByprodDepart;
    }

    @PostMapping("/searchStockAll")
    public JsonResult searchStockAll(@RequestBody Map<String,Object> params){
        PageInfo<StockDto> entityList = corderService.searchStockAll(params);
        Map result=new HashMap<>();
        result.put("total",entityList.getTotal());
        result.put("list",entityList.getList());
        return new JsonResult(1,result);
    }

    @PostMapping("/getCord")
    public JsonResult getCord(@RequestBody Map<String,Object> params) {
        PageInfo<CorderDto> entityList = corderService.getCord(params);
        Map result=new HashMap<>();
        result.put("total",entityList.getTotal());
        result.put("list",entityList.getList());
        return new JsonResult(1,result);
    }

    @PostMapping("/getWorderdetails")
    public JsonResult getWorderdetails(@RequestBody Map<String,Object> params) {
        PageInfo<Corderdetails> entityList = corderService.getCorderdetails(params);
        Map result=new HashMap<>();
        result.put("total",entityList.getTotal());
        result.put("list",entityList.getList());
        return new JsonResult(1,result);
    }

    @GetMapping("/findCorderByStatus")
    public List<CorderDto> findCorderByStatus(Integer checkStatus){
        List<CorderDto> corderAllByStatus = corderService.findCorderByStatus(checkStatus);
        return corderAllByStatus;
    }

    @GetMapping("/findStockdetailsByCheckid")
    public List<Stockdetails> findStockdetailsByCheckid(Integer checkId){
        List<Stockdetails> stockdetails = corderService.findStockdetailsByCheckid(checkId);
        return stockdetails;
    }

    @GetMapping("/findCountByStatus")
    public int findCountByStatus(Integer checkStatus){
        int count = corderService.findCountByStatus(checkStatus);
        return count;
    }
}
